
export default {
  data() {
    return {
      date: new Date()
    }
  },
  created() {

  },
  mounted() {
    const appDom = window.document.getElementById('app')
    if (appDom) {
      appDom.style.backgroundColor = '#030814'
      this.openFullscreen()
    }
    this.oneTimer = setInterval(() => {
      this.date = new Date() // 修改数据date
    }, 1000)
  },
  beforeDestroy() {
    if (this.oneTimer) {
      clearInterval(this.oneTimer) // 在Vue实例销毁前，清除我们的定时器
    }
  },
  methods: {
    openFullscreen() {
      /* 获取(<html>)元素以全屏显示页面 */
      const full = window.document.getElementById('app')
      if (full.RequestFullScreen) {
        full.RequestFullScreen()
        // 兼容Firefox
      } else if (full.mozRequestFullScreen) {
        full.mozRequestFullScreen()
        // 兼容Chrome, Safari and Opera等
      } else if (full.webkitRequestFullScreen) {
        full.webkitRequestFullScreen()
        // 兼容IE/Edge
      } else if (full.msRequestFullscreen) {
        full.msRequestFullscreen()
      }
    },
    dateFormat(time) {
      var date = new Date(time)
      var year = date.getFullYear()
      /* 在日期格式中，月份是从0开始的，因此要加0
    * 使用三元表达式在小于10的前面加0，以达到格式统一  如 09:11:05
    * */
      var month = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1
      var day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate()
      var hours = date.getHours() < 10 ? '0' + date.getHours() : date.getHours()
      var minutes = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()
      var seconds = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds()
      // 拼接
      return year + '-' + month + '-' + day + ' ' + hours + ':' + minutes + ':' + seconds
    }
  }
}

